﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class Admin_Booking_History : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string book_id = "";
        book_id = Request.QueryString["id"].ToString();
        string tabelall = "<table class='layui-table' width='80%'><thead><tr><th>预约单号</th><th>预约人姓名</th><th>联系电话</th><th>身份类型</th><th>预约日期</th><th>具体时间</th><th>设备编号</th><th>所在位置</th><th>预约结果</th><th>备注</th><th>删除</th></tr></thead>";
        SqlConnection conn = new SqlConnection();
        conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionStringProManage"].ConnectionString;
        try
        {
            conn.Open();

            SqlCommand cmddel = new SqlCommand();
            string SQLdel = "update Booking set flag=0 where (book_id=@book_id)";
            cmddel.Connection = conn;
            cmddel.CommandText = SQLdel;
            cmddel.CommandType = CommandType.Text;
            //提交参数 SQL 语句中必须要有@参数
            SqlParameter pid = new SqlParameter("@book_id", SqlDbType.NVarChar, 10);
            pid.Value = book_id;
            cmddel.Parameters.Add(pid);
            cmddel.ExecuteNonQuery();

            SqlCommand cmd = new SqlCommand();
            string SQL = "select book_id,name,phone_num,user_identity,date,time,pro_num,pro_location,condition,remarks from Booking where flag=1";
            cmd.Connection = conn;
            cmd.CommandText = SQL;
            cmd.CommandType = CommandType.Text;
            //提交参数 SQL 语句中必须要有@参数
            //SqlParameter ppro_num = new SqlParameter("@pro_num", SqlDbType.NVarChar, 10);
            //ppro_num.Value = keyword;
            //cmd.Parameters.Add(ppro_num);
            //int flag = 0;            //控制表头仅显示一次
            int k = 0;
            using (SqlDataReader reader = cmd.ExecuteReader())
            {
                int fieldcount = reader.FieldCount;      //取字段总数
                if (!reader.HasRows)            //有数据  ---行
                {
                    LabelText.Text = "<table class='layui-table' style='width: 70%; margin-left:15% '><tr><td>没有数据</td></tr>";
                }
                else
                {
                    string trd = "<tbody>";                     //存储数据
                    while (reader.Read())               //当有数据可读时
                    {
                        trd += "<tr>";          //数据行开始，行以tr起
                        for (int i = 0; i < fieldcount; i++)
                        {   //每一列的内容
                            trd += "<td>" + reader[i].ToString() + "</td>";
                        }
                        trd += "<td><a title='删除'  href = 'Admin_Booking_History.aspx?id=" + reader[0].ToString() + "'><i class='layui-icon'>&#xe640;</i></td></tr>";     //行结束
                        k = k + 1;
                    }
                    LabelText.Text = tabelall + trd + "</tbody></table>";
                    MsgNum.Text = k.ToString();

                }
            }
        }


        finally
        {
            conn.Close();
        }
    }
}